var status = -1;
var selectionLog = [];

function start() {
    action(1, 0, 0)
}
var category = ["HenesysSmall", "HenesysLarge", "HalloweenSmall", "HalloweenLarge", "EthnicSmall", "EthnicLarge", "AntiqueSmall", "AntiqueLarge", "NewYearSmall", "NewYearLarge", "LithCafeSmall", "LithCafeLarge", "HenesysConstruction", "HalloweenConstruction", "CommerzConstruction", "NewYearConstruction", "LithCafeConstruction"];
var name = ["射手村风格小购物包", "射手村风格大购物包", "万圣节小型家具礼包", "万圣节大型家具礼包", "民族风小购物包", "民族风大购物包", "古典风格小购物包", "古典风格大购物包", "东洋风格小购物包", "东洋风格大购物包", "海滨露台小屋小购物包裹", "海滨露台小屋大购物包裹", "射手村风格图纸包", "万圣节风格图纸包裹", "凯梅尔兹风格图纸包", "东洋风格图纸包", "海滨露台小屋图纸包裹"];
var item = [
    [2672062, 2672063, 2672064, 2671051, 2672067, 2672068, 2672065, 2672066, 2672055, 2671004, 2671005, 2671006, 2671040, 2671039, 2671044, 2671049],
    [2672017, 2672061, 2672062, 2672022, 2672023, 2672024, 2671007, 2672060, 2672004, 2672000, 2672001, 2671000, 2672058, 2671003, 2672063, 2672064],
    [2671055, 2671056, 2671058, 2671064, 2671065, 2671066, 2672079, 2672080, 2672084, 2672088, 2672089, 2672090, 2672091, 2672092],
    [2671057, 2671059, 2671060, 2671061, 2671062, 2671063, 2672077, 2672078, 2672077, 2672081, 2672082, 2672083, 2672085, 2672086, 2672087],
    [2672040, 2672039, 2672044, 2671017, 2672043, 2671018, 2671052, 2671045, 2671047, 2671048, 2671043],
    [2672037, 2672038, 2672039, 2671015, 2672010, 2672041, 2672042, 2672059, 2672011, 2672044, 2671017, 2671009, 2671016],
    [2672030, 2672031, 2671010, 2671014, 2672008, 2672009, 2672036, 2671011, 2671012, 2671013, 2671041, 2671042, 2671046, 2671050],
    [2672028, 2672029, 2672030, 2672031, 2672007, 2672032, 2672035, 2672006, 2672033, 2672005, 2672034, 2671010, 2671038],
    [2672098, 2672099, 2671069, 2672105, 2672108, 2672110, 2671070, 2672106, 2671072, 2671073, 2671074, 2671075, 2671076, 2671077, 2671078],
    [2672096, 2671067, 2672097, 2671068, 2672109, 2672103, 2672104, 2672100, 2672101, 2672102, 2672107, 2671079, 2671080, 2671081, 2671082, 2671083],
    [2672123, 2672124, 2672125, 2672126, 2672130, 2672131, 2672138, 2671092, 2671093, 2671094, 2671095, 2671096, 2671097, 2671098, 2631778],
    [2672122, 2672127, 2672128, 2672129, 2672132, 2672133, 2672134, 2672135, 2672121, 2672139, 2671091, 2671114, 2671093, 2672123, 2672124],
    [2670009, 2670010, 2670012, 2670036, 2670014, 2670015, 2670043, 2670044, 2670045, 2670046, 2670047, 2670048, 2670033, 2670034, 2670011],
    [2670050, 2670051, 2670052, 2670053, 2670054, 2670056, 2670057, 2670058, 2670061, 2670060, 2670063, 2670064, 2670066, 2670067, 2670068, 2670069, 2670070, 2670072],
    [2670018, 2670019, 2670022, 2670023, 2670024, 2670025, 2670037, 2670027, 2670038, 2670029, 2670039, 2670032, 2670041, 2670042],
    [2670073, 2670075, 2670076, 2670078, 2670079, 2670081, 2670083, 2670085, 2670086, 2670087],
    [2670089, 2670090, 2670092, 2670095, 2670096, 2670098, 2670099, 2670101, 2670102, 2670111, 2670112, 2670104, 2670105, 2670107, 2670108]
];
var shoppingTime = [3, 6, 6, 12, 4, 8, 5, 10, 6, 12, 6, 12, 12, 16, 16, 16, 16];
var npcs = [9400920, 9400921, 9401160];

function action(f, h, k) {
    if (status == 0 && f == 0) {
        cm.dispose();
        return
    }(f == 1) ? status++ : status--;
    selectionLog[status] = k;
    var d = cm.getNumberFromQuestInfo(500773, "manager");
    var g = npcs[d];
    var l = cm.getNumberFromQuestInfo(500773, "s2");
    var j = cm.getNumberFromQuestInfo(500773, "s3");
    var h = cm.getNpc();
    var e = -1;
    if (status <= e++) {
        cm.dispose()
    } else {
        if (status === e++) {
            cm.setSessionValue("LotteryName", category[h]);
            cm.askAcceptDecline_Bottom("#face0##b" + name[h] + "#k家具选购需要#b" + shoppingTime[h] + "小时#k #r(" + j + "分钟 额外降低加成)#k。你确定要现在出发吗？", 36, g)
        } else {
            if (status === e++) {
                var b = new java.util.Date();
                var a = new java.text.SimpleDateFormat("yy/MM/dd/HH/mm").format(b);
                b.setTime(b.getTime() + Math.max(60 * 1000, shoppingTime[h] * 60 * 60 * 1000 - j * 60 * 1000));
                var c = new java.text.SimpleDateFormat("yy/MM/dd/HH/mm").format(b);
                cm.updateInfoQuest(500778, "reward=" + item[h][cm.rand(0, item[h].length - 1)] + ",Count:" + (cm.rand(1, 100) < l ? 2 : 1) + ";lotteryName=" + category[h] + ";last=" + a + ";bonusCoin=0;t=" + c);
                cm.forceStartQuest(500778, "");
                cm.sendNormalTalk_Bottom("#face1#好的！那我就去找家具了，你慢慢等吧！", 37, g, false, true);
                if (cm.isQuestActive(501025) && (category[h].equals("LithCafeSmall") || name[h].equals("LithCafeLarge") || name[h].equals("LithCafeConstruction"))) {
                    cm.addNumberForQuestInfo(501025, "cnt", 1, 0, 10)
                }
            } else {
                cm.fieldEffect_PlayFieldSound("Sound/UI.img/Invite", 100);
                cm.dispose()
            }
        }
    }
};